package service.impl;

import dao.CollectionDao;
import dao.CommodityDao;
import dao.impl.CollectionDaoImpl;
import dao.impl.CommodityDaoImpl;
import entity.Commodity;
import service.CollectionService;

import java.util.ArrayList;
import java.util.List;

public class CollectionServiceImpl implements CollectionService {
    CollectionDao collectionDao = new CollectionDaoImpl();
    CommodityDao commodityDao = new CommodityDaoImpl();

    @Override
    public int add(int userid, int commId) {
        return collectionDao.add(userid,commId);
    }

    @Override
    public boolean findExist(int userId, int commId) {
        return collectionDao.findExist(userId,commId);
    }

    @Override
    public List<Commodity> findByUserId(int userId,int startPage,int limit) {
        List<Integer> list = collectionDao.findCommIdByUserId(userId,startPage,limit);
        List<Commodity> commList = new ArrayList<>();
        for (Integer item : list){
            commList.add(commodityDao.findById(item));
        }
        return commList;
    }

    @Override
    public int findCountByUserId(int userId) {
        return collectionDao.findCountByUserId(userId);
    }
}
